package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.RechargeBean;
import com.mvp.shq.washer.entity.RechargeMoney;
import com.mvp.shq.washer.rxbus.BusData;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.orhanobut.logger.Logger;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/8/23.
 */

public class RechargeAdapter extends RecyclerView.Adapter<RechargeAdapter.ViewHolder> {
    private Context context;
    private List<RechargeBean> moneys;

    public RechargeAdapter(Context mContext, List<RechargeBean> list) {
        context = mContext;
        moneys = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recharge, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvMoney.setText(moneys.get(position).getLabel()+"元");
        if (moneys.get(position).isSelect()){
            holder.tvMoney.setTextColor(ContextCompat.getColor(context,R.color.white));
            holder.tvMoney.setBackgroundColor(ContextCompat.getColor(context,R.color.money));
        }else {
            holder.tvMoney.setTextColor(ContextCompat.getColor(context,R.color.text_black));
            holder.tvMoney.setBackgroundColor(ContextCompat.getColor(context,R.color.text_color_1));
        }
        holder.tvMoney.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BusData data = new BusData();
                data.setPosition(position);
                RxBus.get().send(EventCode.ON_RECHARGEMONEY_CLICK,data);
            }
        });
    }

    @Override
    public int getItemCount() {
        return moneys.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_recharge_money)
        TextView tvMoney;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            AutoUtils.autoSize(itemView);
        }
    }
}
